<?php
    require_once '../../common/DBHelper.php';
    // 连接数据库
    $conn = conn();
    // sql语句
    $sql = "SELECT * FROM posts ORDER BY views DESC LIMIT 4";
    $res = query($conn, $sql);
    $response = ['code' => 0,'msg' => '操作失败'];
    
    if ($res) {
        $response['code'] = 1;
        $response['msg'] = '操作成功';
        $response['data'] = $res;
    }
    close($conn);
    // 返回给前端
    echo json_encode($response, JSON_UNESCAPED_UNICODE);
